package com.hmall.item.exception;

import com.hmall.item.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 处理异常类
 *
 * @Author Vsunks.v
 * @Date 2022/7/11 15:09
 * @Description: 处理异常类
 * @Created by 15198*/


@Slf4j
@RestControllerAdvice(annotations = {RestController.class, Controller.class})
public class MyExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public Result MyBusinessException(BusinessException bex){

        //记录日志
      log.warn(bex.getMessage());
      //提示给用户
      return Result.error(bex.getMessage());

    }
}
